<template>
  <div class="page-login">
    <div class="page-login__loading">
      身份识别中...
    </div>
  </div>
</template>

<script>
import dbl from "@/utils/dbl";
import { encrypt } from "@/utils/rsaEncrypt";
import { fetchAllList } from "~/admin/api/dict";
import {
  autoLogin,
  getuserbyuserid,
  setIsolation,
  getIsolations,
} from "@/api/login";
import slider from "@/views/wy-login/components/slider.vue";

import Cookies from "js-cookie";

export default {
  name: "Login",
  components: {
    slider,
  },
  data() {
    return {
      isLogin: false,
      userInfo: {},
      isolations: [],
      loginData: {},
      pwFlag: false,
    };
  },
 async  mounted() {
    await this.getUserInfo()
    await this.login()
  },
  methods: {
    async getUserInfo() {
        this.loading = true;
        this.loadingText = "获取用户信息……";
        let userid = "g0ryleukz8954nlkhta1xp"//1.政务微信携带过来，守本
        let data = await getuserbyuserid(userid)//2.调用政务微信官方接口，守本，不知道是代理，还是绝对地址

        this.userInfo = data;
        this.loading = false;
    },
    async login() {
        this.loading = true;
        this.loadingText = "登录中……";
        let {data} = await autoLogin(this.userInfo.telephonenumber)//3.调试成功，登录
        this.loginData = data.data;
        this.doLogin();
        this.loading = false;
    },
    doLogin() {
      const data = this.loginData;
      const token = data.token;
      const userInfo = {
          uid: data.userId
      }
      this.$store.commit("SET_USER", userInfo);
      dbl.set("token", token);
      dbl.set("user", userInfo);
      Cookies.set("dbl-user", JSON.stringify(userInfo), { expires: 30 });
      Cookies.set("dbl-token", JSON.stringify(token), { expires: 30 });
      this.$router.replace({ path: "/risk" });
    }
  },
};
</script>
<style>
.page-login__loading{
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: #999;
}
</style>
